#!/bin/sh
TABLENAME=cdp
SYMBOL_DB_FILE="/root/bin/cdp.sqlite"
echo "create table if not exists $TABLENAME(src text, des text);" | sqlite3 $SYMBOL_DB_FILE

action=$1
args=$2

if [ "$action" = "" ]; then
    action='help'
fi

if [ "$action" = "add" ]; then
    echo "insert into $TABLENAME values('$args' ,'$args');" | sqlite3 $SYMBOL_DB_FILE  
    echo '添加成功'
    exit 0
fi

if [ "$action" = "ls" ]; then
    echo "select src from $TABLENAME;" | sqlite3 $SYMBOL_DB_FILE
    exit 0
fi

if [ "$action" = "rm" ]; then
    echo "delete from $TABLENAME where src='$args';" | sqlite3 $SYMBOL_DB_FILE
    exit 0
fi

if [ "$action" = "help" ]; then
    echo "以下命令:"
    echo "cdp help"
    echo "cdp ls"
    echo "cdp add str"
    echo "cdp rm str"
    exit 0
fi



if [ "$action" = "install" ]; then
    if [ "$args" = "nginx" ]; then


PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#安装依赖环境
yum install -y patch openssl make cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils
#安装PCRE
wget http://download.gshyj.com/download/pcre-8.42.tar.gz
tar zxf pcre-8.42.tar.gz
cd pcre-8.42/
./configure && make && make install
cd ../
#安装NGINX
wget http://download.gshyj.com/download/nginx-1.14.0.tar.gz
tar zxf nginx-1.14.0.tar.gz
cd nginx-1.14.0/
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-http_v2_module
make && make install
cd ../

ln -s /usr/local/lib/libpcre.so.1 /lib
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
#rm -f /usr/local/nginx/conf/nginx.conf
mkdir -p /home/wwwroot/default
chmod +w /home/wwwroot/default
mkdir -p /home/wwwlogs
chmod 777 /home/wwwlogs
chown -R nobody:nobody /home/wwwroot/default


wget -c http://download.gshyj.com/download/init.d.nginx
cp init.d.nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig --level 345 nginx on
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables-save
ldconfig

#wget -c //dn-ghy459.qbox.me/download/nginx.conf
#mv nginx.conf /usr/local/nginx/conf/
/etc/init.d/nginx start


    fi
fi

if [ "$action" = "install" ]; then
    if [ "$args" = "mysql" ]; then
        if [ -f "mysql-boost-8.0.13.tar.gz" ];then
            echo "安装包文件存在"
        else
            echo "安装包文件不存在，需要下载"
            wget http://download.gshyj.com/download/mysql-boost-8.0.13.tar.gz
        fi
        #TODO:
        yum -y install make gcc-c++ cmake bison-devel  ncurses-devel   bison perl perl-devel  perl perl-devel
        tar -zxvf mysql-boost-8.0.13.tar.gz -C /usr/local

        groupadd mysql
        useradd -r -g mysql -s /bin/false mysql
        cd /usr/local/mysql-8.0.13/
        cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
        make
        make install
        




    fi
fi





